<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>5_天气案例-监视简写形式</title>
        <script type="text/javascript" src="../js/vue.js"></script>
    </head>
    <body>
        <div id="demo">
            <h1>今天天气很{{info}}</h1>
            <button @click="changeWeather">切换天气</button>
            <img :src="url">    
        </div>
    </body>

    <script type="text/javascript">
        Vue.config.productionTip = false;

        new Vue({
            el: '#demo',
            data: {
                isHot: true,
                url: 'https://s3.ax1x.com/2020/12/13/reC1IA.jpg'
            },
            computed: {
              info(){
                  return this.isHot ? '炎热' : '凉爽'
              }  
            },
            methods: {
                changeWeather(){
                    this.isHot = !this.isHot
                }
            },
            watch: {
                // 标准写法
                // #region
                // isHot: {
                //     handler(value){
                //         if(value) this.url = 'https://s3.ax1x.com/2020/12/13/reC1IA.jpg'
                //         else this.url = 'https://s3.ax1x.com/2020/12/13/reCaqg.jpg'
                //     }
                // }
                // #endregion

                isHot(value){
                    if(value) this.url = 'https://s3.ax1x.com/2020/12/13/reC1IA.jpg'
                    else this.url = 'https://s3.ax1x.com/2020/12/13/reCaqg.jpg'
                 }

            }
        })
        
    </script>
</html>